<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="utf-8">
    <title>在线心理测评管理系统</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport"
          content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
    <link rel="stylesheet" href="../layuiadmin/layui/css/layui.css" th:href="@{/layuiadmin/layui/css/layui.css}"
          media="all">
    <link rel="stylesheet" href="../layuiadmin/style/admin.css" th:href="@{/layuiadmin/style/admin.css}" media="all">
    <link rel="stylesheet" href="../layuiadmin/style/login.css" th:href="@{/layuiadmin/style/login.css}" media="all">
</head>
<body>

<div class="layadmin-user-login layadmin-user-display-show" id="LAY-user-login" style="display: none;">

    <div class="layadmin-user-login-main">
        <div class="layadmin-user-login-box layadmin-user-login-header">
            <h2>在线心理测评平台</h2>
            <p></p>
            <p>请登入后使用</p>
        </div>
        <div class="layadmin-user-login-box layadmin-user-login-body layui-form">
            <div class="layui-form-item">
                <label class="layadmin-user-login-icon layui-icon layui-icon-username"
                       for="LAY-user-login-username"></label>
                <input type="text" name="username" id="LAY-user-login-username" lay-verify="required" placeholder="用户名"
                       class="layui-input">
            </div>
            <div class="layui-form-item">
                <label class="layadmin-user-login-icon layui-icon layui-icon-password"
                       for="LAY-user-login-password"></label>
                <input type="password" name="password" id="LAY-user-login-password" lay-verify="required"
                       placeholder="密码" class="layui-input">
            </div>
            <div class="layui-form-item">
                <div class="layui-row">
                    <div class="layui-col-xs7">
                        <label class="layadmin-user-login-icon layui-icon layui-icon-vercode"
                               for="LAY-user-login-vercode"></label>
                        <input type="text" name="vercode" id="LAY-user-login-vercode" lay-verify="required"
                               placeholder="图形验证码" class="layui-input">
                    </div>
                    <div class="layui-col-xs5">
                        <div style="margin-left: 10px;">
                            <img src="/defaultKaptcha" class="layadmin-user-login-codeimg"
                                 id="LAY-user-get-vercode" alt="点击切换验证码">
                        </div>
                    </div>
                </div>
            </div>
            <div class="layui-form-item">
                <button class="layui-btn layui-btn-fluid" lay-submit lay-filter="LAY-user-login-submit">登 入</button>
            </div>
        </div>
    </div>

    <div class="layui-trans layadmin-user-login-footer">

        <p>© 2022 <a href="javascript:;" target="_blank">在线心理咨询服务平台</a></p>
    </div>
</div>
<script src="../layuiadmin/layui/layui.js" th:src="@{/layuiadmin/layui/layui.js}"></script>
<script>
    layui.config({
        base: '../../layuiadmin/' //静态资源所在路径
    }).extend({
        index: 'lib/index' //主入口模块
    }).use(['index', 'user'], function () {
        var $ = layui.$
            , form = layui.form
            , router = layui.router()

        form.render();

        //提交
        form.on('submit(LAY-user-login-submit)', function (obj) {

            //请求登入接口
            $.ajax({
                type: 'POST',
                url: '/login_do',
                data: JSON.stringify(obj.field),
                contentType: "application/json;charset=UTF-8",
                success: function (result) {
                    if (result == 'success') {
                        layer.msg('登入成功', {
                            offset: '15px'
                            , icon: 1
                            , time: 1500
                        }, function () {
                            location.href = '../'; //
                        });
                    } else if (result == 'userNull') {
                        layer.msg('用户不存在！', {
                            offset: '15px'
                            , icon: 1
                            , time: 1000
                        }, function () {
                            location.href = '/login'; //
                        });
                    } else if (result == 'passwordError') {
                        layer.msg('账号或者密码错误！', {
                            offset: '15px'
                            , icon: 1
                            , time: 1000
                        }, function () {
                            location.href = '/login'; //
                        });
                    } else if (result == 'vrifyCodeErroe') {
                        layer.msg('验证码错误！', {
                            offset: '15px'
                            , icon: 1
                            , time: 1000
                        }, function () {
                            location.href = '/login'; //刷新验证码
                        });
                    }
                },
                error: function (result) {
                    alert("数据异常---->" + result.toString());
                }
            });

        });


        //实际使用时记得删除该代码
        layer.msg('欢迎登入系统！', {
            offset: '15px'
            , icon: 1
        });

    });
</script>
<script>
    layui.define('form', function (exports) {
        var $ = layui.$
            , layer = layui.layer
            , laytpl = layui.laytpl
            , setter = layui.setter
            , view = layui.view
            , admin = layui.admin
            , form = layui.form;

        var $body = $('body');

        //自定义验证
        form.verify({
            nickname: function (value, item) { //value：表单的值、item：表单的DOM对象
                if (!new RegExp("^[a-zA-Z0-9_\u4e00-\u9fa5\\s·]+$").test(value)) {
                    return '用户名不能有特殊字符';
                }
                if (/(^\_)|(\__)|(\_+$)/.test(value)) {
                    return '用户名首尾不能出现下划线\'_\'';
                }
                if (/^\d+\d+\d$/.test(value)) {
                    return '用户名不能全为数字';
                }
            }

            //我们既支持上述函数式的方式，也支持下述数组的形式
            //数组的两个值分别代表：[正则匹配、匹配不符时的提示文字]
            , pass: [
                /^[\S]{6,12}$/
                , '密码必须6到12位，且不能出现空格'
            ]
        });
        //更换图形验证码
        $body.on('click', '#LAY-user-get-vercode', function () {
            var othis = $(this);
            console.debug(othis.toString());
            this.src = '/defaultKaptcha?t=' + new Date().getTime()
        });

        //对外暴露的接口
        exports('user', {});
    });
</script>
</body>
</html>